/*     */ package com.cr.framework.shiro.service;
/*     */ 
/*     */ import com.cr.common.core.domain.entity.SysUser;
/*     */ import com.cr.common.enums.UserStatus;
/*     */ import com.cr.common.exception.user.CaptchaException;
/*     */ import com.cr.common.exception.user.UserBlockedException;
/*     */ import com.cr.common.exception.user.UserDeleteException;
/*     */ import com.cr.common.exception.user.UserNotExistsException;
/*     */ import com.cr.common.exception.user.UserPasswordNotMatchException;
/*     */ import com.cr.common.utils.MyDateUtils;
/*     */ import com.cr.common.utils.MessageUtils;
/*     */ import com.cr.common.utils.ServletUtils;
/*     */ import com.cr.common.utils.ShiroUtils;
/*     */ import com.cr.framework.manager.AsyncManager;
/*     */ import com.cr.framework.manager.factory.AsyncFactory;
/*     */ import com.cr.system.service.ISysUserService;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Component;
/*     */ import org.springframework.util.StringUtils;
/*     */ 
/*     */ @Component
/*     */ public class SysLoginService {
/*     */   @Autowired
/*     */   private SysPasswordService passwordService;
/*     */   
/*     */   @Autowired
/*     */   private ISysUserService userService;
/*     */   
/*     */   public SysUser login(String username, String password) {
/*  44 */     if ("captchaError".equals(ServletUtils.getRequest().getAttribute("captcha"))) {
/*  46 */       AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, "Error", MessageUtils.message("user.jcaptcha.error", new Object[0]), new Object[0]));
/*  47 */       throw new CaptchaException();
/*     */     } 
/*  50 */     if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
/*  52 */       AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, "Error", MessageUtils.message("not.null", new Object[0]), new Object[0]));
/*  53 */       throw new UserNotExistsException();
/*     */     } 
/*  56 */     if (password.length() < 5 || password
/*  57 */       .length() > 20) {
/*  59 */       AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, "Error", MessageUtils.message("user.password.not.match", new Object[0]), new Object[0]));
/*  60 */       throw new UserPasswordNotMatchException();
/*     */     } 
/*  64 */     if (username.length() < 2 || username
/*  65 */       .length() > 20) {
/*  67 */       AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, "Error", MessageUtils.message("user.password.not.match", new Object[0]), new Object[0]));
/*  68 */       throw new UserPasswordNotMatchException();
/*     */     } 
/*  72 */     SysUser user = this.userService.selectUserByLoginName(username);
/*  86 */     if (user == null) {
/*  88 */       AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, "Error", MessageUtils.message("user.not.exists", new Object[0]), new Object[0]));
/*  89 */       throw new UserNotExistsException();
/*     */     } 
/*  92 */     if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
/*  94 */       AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, "Error", MessageUtils.message("user.password.delete", new Object[0]), new Object[0]));
/*  95 */       throw new UserDeleteException();
/*     */     } 
/*  98 */     if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
/* 100 */       AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, "Error", MessageUtils.message("user.blocked", new Object[] { user.getRemark() }), new Object[0]));
/* 101 */       throw new UserBlockedException();
/*     */     } 
/* 104 */     this.passwordService.validate(user, password);
/* 106 */     AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, "Success", MessageUtils.message("user.login.success", new Object[0]), new Object[0]));
/* 107 */     recordLoginInfo(user);
/* 108 */     return user;
/*     */   }
/*     */   
/*     */   public void recordLoginInfo(SysUser user) {
/* 136 */     user.setLoginIp(ShiroUtils.getIp());
/* 137 */     user.setLoginDate(MyDateUtils.getNowDate());
/* 138 */     this.userService.updateUserInfo(user);
/*     */   }
/*     */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-framework-4.7.0.jar!\com\cr\framework\shiro\service\SysLoginService.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */